package com.itheima._02自定义异常;

/**
 * @Description Demo021
 * @Author GreenHand_Lu
 * @Date 2025-07-19
 */
public class Demo021 {

    public static void main(String[] args) throws AgeIllegalException {
        setAge(201);//这里会抛出编译时异常，结束程序
        setAge(100);
    }
    public static void setAge(int age)throws AgeIllegalException{
        if(age<0 || age>200){
            throw new AgeIllegalException("年龄不合法");
        }
        System.out.println("年龄为："+age);
    }
}